# -*- coding:utf-8 -*-
import pyDes
import base64
import json

class CodecUtils:
    @staticmethod
    def encode_with_contract(text, secret):
        des3 = pyDes.triple_des(secret, pyDes.ECB, padmode=pyDes.PAD_PKCS5)
        encrypted = des3.encrypt(text)
        result = base64.standard_b64encode(encrypted)
        return result

    @staticmethod
    def decode_with_contract(text, secret):
        encrypted = base64.standard_b64decode(text)
        des3 = pyDes.triple_des(secret, pyDes.ECB, padmode=pyDes.PAD_PKCS5)
        result = des3.decrypt(encrypted)
        return result

    @staticmethod
    def decode_with_contract_to_object(text, secret):
        json_string = CodecUtils.decode_with_contract(text, secret)
        obj = json.loads(json_string)
        return obj


if __name__ == '__main__':
    text = "{\"Mobile\": \"13312345678\", \"Password\": \"12345678\", \"RegisterRole\": 5}"

    key = "1e469f986f5d4991a83b95d4"
    #print (CodecUtils.encode_with_contract(text, key))
    de = "6p6uJ0io78z9w9Lfk+yIYO/fF2EhCfvxW0qrErb2D8PabJN7SSmell0VB1vzZ05mau0X91G+1QyaF1nY5LKwnrWS1UjP5EXHTAKk/tk7rQNsCfcInI7lFiJ2Hu9M+iJQ+At/CW+vh7rKfAqjuYq0xpPMSyhaXcGQmuZ8F7FqzChaVAAq+jkZ/YHyABSRX2HhTkFp76mXa5D7mvFui+q4Vc4exgs7LiFKGKaE/eOoTAtPECGyQM2mrCAF3R9J5IHsEyqzlz8RRGXWlMFHIOLx20Rn/YXJPhsL2gN2SRqUe+dhXmsxerFTS3AivZ0m2b3zzOMP8+H+pJssxhxcu2peHd7xa4SL1K88vaWkht+b5rGjkZNLHABTCtg7Wk917LbkGJoFpNI+OamioY2vsMloAVEZS5Lju1S591MRcs7WMF1UYIJDPBGeynlKn0KyQClA3iFrGMy2zfqKX2J3Nt5Jb7WdE4VWujyEGIYSz6jnxJBFT4FkgV+g8+NRU3NT5OnzFPBMQjfHw1vfN/ReFfIoN8S4/xMfqxnujh41QdOumY+UuA68ERa+QJsIJ/psdQ6d99xQj+wD++Xcn5F7gKbarGYyZq5o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